package view;

public class Coord {

	// FIELDS
	private int x;
	private int y;
	
	// CONSTRUCTERS
	public Coord(int x, int y) {
		if (x < 0) {
			throw new IllegalArgumentException("x argument < 0");
		}
		if (y < 0) {
			throw new IllegalArgumentException("y argument < 0");
		}
		this.x = x;
		this.y = y;
	}
	
	public Coord() {
		this(0, 0);
	}

	// METHODS
	/**
	 * @return the x
	 */
	public int getX() {
		return x;
	}
	
	/**
	 * @return the y
	 */
	public int getY() {
		return y;
	}
	
	public double getDistance(Coord c) {
		if (c == null) {
			throw new IllegalArgumentException("coord argument is null");
		}
		int x = (int) Math.pow(Math.abs(this.getX() - c.getX()), 2);
		int y = (int) Math.pow(Math.abs(this.getY() - c.getY()), 2);
		
		double dist = Math.sqrt(x + y);
		
		return dist;
	}
	
	/**
	 * @param x the x to set
	 */
	public void setX(int x) {
		this.x = x;
	}

	/**
	 * @param y the y to set
	 */
	public void setY(int y) {
		this.y = y;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Coord other = (Coord) obj;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}
	
}
